/**
 * 
 */
package neptune.manager.validator.rules.topology;

import java.util.ArrayList;

import neptune.manager.model.topology.Link;
import neptune.manager.model.topology.Topology;
import neptune.manager.utils.Logger.MessageType;
import neptune.manager.validator.ValidatorResult;
import neptune.manager.validator.ValidatorRule;
import neptune.manager.validator.Validator.Status;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class TopologyLinksUniquenessRule extends ValidatorRule<Topology> {

	@Override
	public String getName() {
		return "TopologyLinksUniquenessRule";
	}

	@Override
	protected ValidatorResult validationAlgorithm(Topology toValidate,
			ValidatorResult result) {

		ArrayList<String> ids = new ArrayList<String>(0);

		for (Link link : toValidate.getLinks()) {
			if (ids.contains(link.getId())) {
				result.setStatus(Status.ERROR);
				result.getLog().addMessage(
						"Duplicated link '" + link.getId() + "'",
						MessageType.ERROR);
			} else
				ids.add(link.getId());
		}

		return result;
	}

}
